package com.hns.can.master.web;

import com.hns.can.common.web.BaseController;
import com.hns.can.master.entity.BaseQuickLinkEntity;
import com.hns.can.master.service.BaseQuickLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

/**
 * 云总线快捷链接控制类
 *
 * @author jeff
 * @email 835264047@qq.com
 */
@Controller
@RequestMapping("/baseQuickLink")
public class BaseQuickLinkController extends BaseController {

    @Autowired
    private BaseQuickLinkService baseQuickLinkService;

    /**
     * 得到云总线快捷链接的信息
     *
     * @return
     */
    @RequestMapping("getQuickLinks")
    @ResponseBody
    public Object getQuickLinks() {
        List<BaseQuickLinkEntity> list = baseQuickLinkService.getQuickLinks();

        return this.getReturnResult(list);
    }

    /**
     * 保存云总线快捷链接的信息
     *
     * @param names
     * @param urls
     * @param sequences
     * @return
     */
    @RequestMapping("saveQuickLinks")
    @ResponseBody
    public Object saveQuickLinks(String[] names,
                                 String[] urls,
                                 String[] logos,
                                 BigDecimal[] sequences) throws Exception {
        baseQuickLinkService.saveQuickLinks(names, logos, urls, sequences);

        return this.getReturnResult();
    }

    @RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
    @ResponseBody
    public Object uploadImage(@RequestParam MultipartFile[] myfiles, String uploadPath, HttpServletRequest request, HttpServletResponse response) throws Exception {
        baseQuickLinkService.fileUpload(myfiles, uploadPath, request, response);
        return null;
    }

    @RequestMapping("/readImage")
    @ResponseBody
    public Object readImage(String uploadPath, HttpServletRequest request, HttpServletResponse response) throws Exception {
        baseQuickLinkService.readImage(uploadPath, request, response);
        return this.getReturnResult();
    }


}
